package org.dromara.pe.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.pe.domain.vo.TaskReservationVo;
import org.dromara.pe.domain.bo.TaskReservationBo;
import org.dromara.pe.service.ITaskReservationService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 预约审核名单
 *
 * @author Lion Li
 * @date 2024-09-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/pe/taskReservation")
public class TaskReservationController extends BaseController {

    private final ITaskReservationService taskReservationService;

    /**
     * 查询预约审核名单列表
     */
    @SaCheckPermission("pe:taskReservation:list")
    @GetMapping("/list")
    public TableDataInfo<TaskReservationVo> list(TaskReservationBo bo, PageQuery pageQuery) {
        return taskReservationService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出预约审核名单列表
     */
    @SaCheckPermission("pe:taskReservation:export")
    @Log(title = "预约审核名单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TaskReservationBo bo, HttpServletResponse response) {
        List<TaskReservationVo> list = taskReservationService.queryList(bo);
        ExcelUtil.exportExcel(list, "预约审核名单", TaskReservationVo.class, response);
    }

    /**
     * 获取预约审核名单详细信息
     *
     * @param reservationId 主键
     */
    @SaCheckPermission("pe:taskReservation:query")
    @GetMapping("/{reservationId}")
    public R<TaskReservationVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long reservationId) {
        return R.ok(taskReservationService.queryById(reservationId));
    }

    /**
     * 新增预约审核名单
     */
    @SaCheckPermission("pe:taskReservation:add")
    @Log(title = "预约审核名单", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TaskReservationBo bo) {
        return toAjax(taskReservationService.insertByBo(bo));
    }

    /**
     * 修改预约审核名单
     */
    @SaCheckPermission("pe:taskReservation:edit")
    @Log(title = "预约审核名单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TaskReservationBo bo) {
        return toAjax(taskReservationService.updateByBo(bo));
    }

    /**
     * 删除预约审核名单
     *
     * @param reservationIds 主键串
     */
    @SaCheckPermission("pe:taskReservation:remove")
    @Log(title = "预约审核名单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{reservationIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] reservationIds) {
        return toAjax(taskReservationService.deleteWithValidByIds(List.of(reservationIds), true));
    }
}
